package common.html;

import org.apache.commons.lang.StringUtils;

public class ScriptTag extends Tag
{

    private String src = "";
    private String type = "text/javascript";

    public static String ATTR_SRC = "src";

    public static String ATTR_TYPE = "type";

    public ScriptTag()
    {
        super();
        reloadAttr();
    }

    public ScriptTag(String src)
    {
        this();
        setSrc(src);
        reloadAttr();
    }

    public String getTagName()
    {
        return "Script";
    }

    public void reloadAttr()
    {
        putAttr(ATTR_TYPE, type);
        if (StringUtils.isNotBlank(src))
        {
            putAttr(ATTR_SRC, src);
        }
    }

    public String getSrc()
    {
        return src;
    }

    public void setSrc(String src)
    {
        this.src = src;
    }

    public String getType()
    {
        return type;
    }

    public void setType(String type)
    {
        this.type = type;
    }

    public ScriptTag javaScript(String str)
    {
        content(str);
        return this;
    }

    public ScriptTag apped(String script)
    {
        String newContent = "";
        if (StringUtils.isNotBlank(this.content))
        {
            newContent = this.content;
        }

        newContent = newContent.concat(script);
        content(newLine(newContent));
        return this;
    }
}
